package com.liufei.class02;

import com.liufei.class01.Code07_SelectSort;

public class Code03_Comp {

    public static int[] lenRandomValueRandom(int maxLen, int maxValue) {
        int len = (int) (Math.random() * maxLen);
        int[] arr = new int[len];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * maxValue);
        }
        return arr;
    }


    public static boolean isSorted(int[] arr) {
        if (arr.length < 2) {
            return true;
        }
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max > arr[i]) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int maxLen = 1000;
        int maxValue = 10000;
        int times = 100000;
        for (int i = 0; i < times; i++) {
            int[] arr = lenRandomValueRandom(maxLen, maxValue);
            // 测试选择排序
            Code07_SelectSort.selectSort(arr);
            if (!isSorted(arr)) {
                System.out.println("排序有问题");
            }
        }
    }
}
